package com.itheima.Array.BinarySearch;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-07-27 22:14
 **/
public class SerchInsert {
    public int searchInsert(int nums[],int target) {
        int length=nums.length;
        int left=0;
        int right=length-1;
        while (left<=right){
            int middle=left+((right-left)>>1);
            if (nums[middle]==target){
                return middle;
            } else if (nums[middle]>target){
                right=middle-1;
            } else if (nums[middle]<target){
                left=middle+1;
            }

        }
        return left;
    }
}
